package com.xja.dubbo.control;

import com.xja.dubbo.entity.Bookinfo;
import com.xja.dubbo.entity.Orderinfo;
import com.xja.dubbo.entity.Userinfo;
import com.xja.dubbo.service.BookInfoService;
import com.xja.dubbo.service.OrderInfoService;
import com.xja.dubbo.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.io.UnsupportedEncodingException;
import java.util.List;

/**
 * 作者：罗帅
 * 当前类所在包：com.xja.dubbo.control
 * 创建时间：2022/8/18下午 1:58 星期四
 * 此类简介：
 */
@RestController
public class DemoController {
    @Autowired
    private BookInfoService bookInfoService;
    @Autowired
    private UserInfoService userInfoService;
    @Autowired
    private OrderInfoService orderInfoService;

    public DemoController() {
        System.out.println("创建了DemoController对象");
    }

    @GetMapping("/book")
    public List<Bookinfo> queryBook(){
        System.out.println("查询所有的图书信息");


        List<Bookinfo> bookInfoList = bookInfoService.findAll();
        System.out.println("结果为："+bookInfoList);

        return bookInfoList;
    }

    @GetMapping("/user")
    public List<Userinfo> queryUser(){
        System.out.println("查询所有的用户信息");
        List<Userinfo> userinfoList = userInfoService.findAll();
        System.out.println("结果为："+userinfoList);
        return userinfoList;
    }

    @PostMapping("/order")
    public String addOrder(@RequestBody Orderinfo orderinfo)  {
        System.out.println("orderinfo---->"+orderinfo);
        int n = orderInfoService.addOrder(orderinfo);
        System.out.println("n---->"+n);
        if(n>0){
            return "1";
        }
        return "0";
    }

}
